<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>


  <script type="text/javascript">

    var arr = ['one', 'two', 'three','4444','1111'];
    var obj = {};
    var temp = []
    // 数组里面字符串的长度统计
    // 答案 { '3': 2, '5': 1 }


    for (let i = 0; i < arr.length; i++) {
      temp.push(arr[i].length)
    }
    
    for (var i = 0; i < temp.length;) {
      var count = 0;
      for (var j = i; j < temp.length; j++) {
        if (temp[i] == temp[j]) {
          count++;
        }
      }
      obj[temp[i]] = count
      i += count;
    }
    console.log(obj)





// -------扩-----------展-----------------------------------------

    var _arr = ['旅行箱', '旅行箱', '小米', '大米'];
    var _res = []; // 
    _arr.sort();
    for (var i = 0; i < _arr.length;) {
      var count = 0;
      for (var j = i; j < _arr.length; j++) {
        if (_arr[i] == _arr[j]) {
          count++;
        }
      }
      _res.push([_arr[i], count]);
      i += count;
    }
    //_res 二维数维中保存了 值和值的重复数
    var _newArr = [];
    for (var i = 0; i < _res.length; i++) {
      // console.log(_res[i][0] + "重复次数:" + _res[i][1]);
      _newArr.push(_res[i][0] + 'X' + _res[i][1]);
    }
    console.log(_newArr);    // ["大米X1", "小米X1", "旅行箱X2"]






    // // obj[key] = 9
    // // obj.a = '添加'
    // console.log(obj)         // {a: "添加"}
  </script>
</body>

</html>